'use strict';
const requireEx=require('yi-require');
const lookup = require('yi-lookup');

const beforeSend = function (req,body,callback) {
    let dataList = (body.data instanceof Array) ? body.data : body.data.items;
    let lookupList = [];
    lookupList.push({
        from: "user",
        localField: "userId",
        foreignField: "_id",
        project:{createTime:0,lastModifyDate:0}
    });
    lookup.lookup(req.mongo, dataList, lookupList, (e, r) => {
        callback(null, body);
    });
};

const middleware =(req, res, next)=>{
    req.beforeSend = beforeSend;
    next();
};

module.exports = {
    middleware: middleware,
    description:'获取霸屏信息',
    handler: requireEx('yi-restful').r('dominating')
};
